package com.zlsy.learning.leetcode.arraycorrelation.array532;


import java.util.HashMap;
import java.util.Map;

/**
 * @author zhouliang
 * @date 2020/5/26 17:38
 */
public class FindPairs {

    private static int findPairs(int[] nums, int k) {

        if (k < 0) {
            return 0;
        }

        Map<String, String> map = new HashMap<>(nums.length);
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] - nums[j] == k || nums[i] - nums[j] == -k) {
                    System.err.println("a=" + nums[i] + " b=" + nums[j]);
                    String key = nums[i] + ":" + nums[j];
                    String value = nums[j] + ":" + nums[i];
                    if (map.size() == 0) {
                        map.put(key, value);
                    }
                    if (!map.containsKey(key) && !map.containsKey(value)) {
                        map.put(key, value);
                    }
                }
            }
        }
        return map.size();
    }

    public static void main(String[] args) {
//        int[] nums = new int[]{3, 1, 4, 1, 5};
//        int pairs = findPairs(nums, 2);
//        int[] nums = new int[]{1, 3, 1, 5, 4};
//        int pairs = findPairs(nums, 0);
        int[] nums = new int[]{1, 2, 3, 4, 5};
        int pairs = findPairs(nums, 1);
        System.out.println(pairs);
    }
}
